home *** CD-ROM | disk | FTP | other *** search
- //extrudes an object away from a light, for faces away from the light
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //...shadows depreciated...
-
- //world,view,projection transforms
- float4x4 matWorld, matViewProj;
-
- //light position (in world space)
- float4 lightPos;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Normal : NORMAL;
- //float2 Tex0 : TEXCOORD0;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- //float2 Tex0 : TEXCOORD0;
- //float4 Color : COLOR;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //move us to world space
- In.Pos.xyz-=In.Normal.xyz*0.25f; //pull in tiny bit so wrong surfaces don't get shadowed
- float4 pos=mul(matWorld,In.Pos);
- float4 norm=mul(matWorld,In.Normal.xyz);
-
- const float EXTRUDE_DIST=10000.0f;
-
- //calc direction from light to vert
- float3 rayDir=normalize(pos.xyz-lightPos.xyz);
-
- //stuff on the back side should be extruded
- float sideCheck=dot(norm,rayDir);
- if (sideCheck>0) //back side
- {
- //push vert in direction of ray
- pos.xyz+=rayDir*EXTRUDE_DIST;
- }
-
- //calc transformed position
- Out.Pos=mul(matViewProj,pos);
-
- //copy tex coord
- //Out.Tex0=In.Tex0;
-
- //plain color
- //Out.Color=float4(1,1,1,1);
-
- //spit out the results
- return Out;
- }
-